package cn.keepme.ep.common.event;

import java.io.Serializable;
import java.util.Map;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

/**
 * 消息发送器，将消息发送到消息队列中
 * @author wupan
 *
 */
public class Sender {


	private JmsTemplate jmsTemplate;

	private Destination destination ;
	
	private Destination responseDestination;
	
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}

	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

	public Destination getDestination() {
		return destination;
	}

	public void setDestination(Destination destination) {
		this.destination = destination;
	}

	public Destination getResponseDestination() {
		return responseDestination;
	}

	public void setResponseDestination(Destination responseDestination) {
		this.responseDestination = responseDestination;
	}

	/**
	 * 发送消息方法，将httpMsgMode发送到消息队列中
	 * @param httpMsgMode
	 * @return
	 */
//	public boolean send(SysEvent event){
//		
//		jmsTemplate.convertAndSend(destination, event);
//		
//		return true;
//	}
//	public boolean send(Map<String,Object> event){
//		
//		jmsTemplate.convertAndSend(destination, event);
//		
//		return true;
//	}
	public void send(final Serializable event) {  
	     
	      jmsTemplate.send(destination, new MessageCreator() {  
	          public Message createMessage(Session session) throws JMSException {  
	              ObjectMessage objectMessage = session.createObjectMessage(event);  
//	              objectMessage.setJMSReplyTo(responseDestination);  
	              return objectMessage;  
	          }  
	      });  
	  }
}
